package com.ww.microrpc.netty.protocol;

import com.ww.microrpc.netty.Constant;

/**
 * RPC Response
 *
 * @author ww
 */
public class ResponseMessage implements Message {
    private static final long serialVersionUID = 8215493329459772524L;

    private boolean success;
    private int requestId;
    private String errorMessage;
    private Object result;

    public static ResponseMessage failureResponse(int requestId, String errorMessage) {
        ResponseMessage response = new ResponseMessage();
        response.setSuccess(false);
        response.setErrorMessage(errorMessage);
        response.setRequestId(requestId);
        return response;
    }

    public static ResponseMessage successResponse(int requestId, String message) {
        ResponseMessage response = new ResponseMessage();
        response.setSuccess(true);
        response.setResult(message);
        response.setRequestId(requestId);
        return response;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    @Override
    public int getMessageType() {
        return Constant.MessageType.RpcResponse;
    }

    @Override
    public int getRequestId() {
        return requestId;
    }

    public void setRequestId(int requestId) {
        this.requestId = requestId;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }
}
